/*
 * CS_REQ_AI_BATTLE_RESULT.cpp
 *
 *  Created on: 2013. 10. 28.
 *      Author: jjaehuny
 */

#include "../../Command.h"

#include "../../User.h"
#include "../../NLogic/BattleAfterEffect.h"

#include <ctime>

namespace ProjectZ { namespace NCommand {

void Command::CS_REQ_AI_BATTLE_RESULT(User * pUser, ::Network::Packet * pPacket)
{
	/*
	// PVP AI로 진행 결과 확인
	CS_REQ_AI_BATTLE_RESULT			0x131f
	{

	}

	SC_REQ_AI_BATTLE_RESULT			0x1320
	{
		s16	ack;							/// 1:결과있음 ,  -1 결과 없음
		u8	u8battle_type;					/// 0:PVP, 1: PK
		u8	u8win_rank;						/// PVP : (0: 패배, 1: 승리), PK : (순위)
		s16	s16win_point;					/// 승점 (PVP만 해당)
		s16	s16evolve_point;				/// 진화포인트
		u8 u8remain_second;					/// 남은 후유증 시간
	}
	 */

	PREPARE_PACKET;

	NLogic::BattleAfterEffect * battleAfterEffect = pUser->GetBattleAfterEffect();
	if (NULL == battleAfterEffect)
	{
		DEBUGLOG("CS_REQ_AI_BATTLE_RESULT NULL == battleAfterEffect");
		return;
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pAck << static_cast<int16_t>(battleAfterEffect->GetData()._hasData);
	* pAck << static_cast<uint8_t>(battleAfterEffect->GetData()._battle_type);
	* pAck << static_cast<uint8_t>(battleAfterEffect->GetData()._winRank);
	* pAck << static_cast<int16_t>(battleAfterEffect->GetData()._win_point);
	* pAck << static_cast<int16_t>(battleAfterEffect->GetData()._evolve_point);


	if (true == pUser->EndBattle_afterEffect())
	{
		* pAck << static_cast<uint8_t>(0);
	}
	else
	{
		std::time_t t = std::time(0);  // t is an integer type
		unsigned int nTime = t;

		int gab = pUser->GetUserInfo().battle_aftereffect_time - nTime;
		* pAck << static_cast<uint8_t>(gab);
	}

	pAck->MakePacket(CMD_SC_REQ_AI_BATTLE_RESULT);
	pUser->Send(pAck);

	battleAfterEffect->GetData().Clear();
}

} /*NCommand*/ } /*ProjectZ*/

